package com.pignest.hotel.module.user.ui;

import java.util.List;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listhead;
import org.zkoss.zul.Listheader;
import org.zkoss.zul.Listitem;

import com.pignest.hotel.beans.User;
import com.pignest.hotel.service.UserService;
import com.pignest.hotel.spring.Services;
import com.pignest.hotel.util.DateUtil;
import com.pignest.hotel.util.WhereCreator;

public class UserListbox extends Listbox {

	private UserService userService;
	
	private String orgId;//查所属部门
	
	public UserListbox(){
		userService=Services.getUserService();
	}
	public void onCreate() {
		this.setHead();
		this.Query();
	}
	public void Query(){
		this.getItems().clear();
		StringBuffer hql=new StringBuffer();
		WhereCreator where =new WhereCreator();
		hql.append(" from User b where 1=1 ");
		if(this.orgId!=null&&!this.orgId.equals("")){
			hql.append(" and b.orgid = '"+this.orgId+"'");
		}
		List<User> userList =userService.find(hql.toString());
		for(int i=0;i<userList.size();i++){
			User user = userList.get(i);
			Listitem listitem = new Listitem();
			
			listitem.setValue(user.getId());
			listitem.setParent(this);
			listitem.appendChild(new Listcell(Integer.toString(i+1)));
			listitem.appendChild(new Listcell(user.getName()));
			listitem.appendChild(new Listcell(user.getWorkNumber()));
			listitem.appendChild(new Listcell(user.getCardNumber()));
			listitem.appendChild(new Listcell(user.getPhone()));
			listitem.appendChild(new Listcell(user.getGender()));
			listitem.addEventListener(Events.ON_CLICK,  new EventListener(){
				public void onEvent(Event event) throws Exception {   
					System.out.println("***********dfdf测试是否能获得单击事件的处理************");
				}
			});
		}
	}
	public void setHead(){
		Listhead head =new Listhead();
		head.setParent(this);
		head.setSizable(true);
		Listheader header =new Listheader("索引");
		header.setWidth("55px");
		header.setParent(head);
		
		Listheader header1 =new Listheader("姓名");
		header1.setWidth("100px");
		header1.setSort("auto");
		header1.setParent(head);
		
		Listheader header2 =new Listheader("账号");
		header2.setWidth("100px");
		header2.setParent(head);
		
		Listheader header3 =new Listheader("卡号");
		header3.setWidth("50px");
		header3.setParent(head);
		
		Listheader header4 =new Listheader("职务");
		header4.setWidth("100px");
		header4.setParent(head);
		
		Listheader header5 =new Listheader("手机");
		header5.setWidth("80px");
		header5.setParent(head);
		
		Listheader header6 =new Listheader("邮件");
		header6.setWidth("100px");
		header6.setParent(head);
		
		Listheader header7 =new Listheader("生日");
		header7.setWidth("100px");
		header7.setParent(head);
		
		Listheader header8 =new Listheader("性别");
		header8.setWidth("100px");
		header8.setParent(head);
		
		Listheader header9 =new Listheader("籍贯");
		header9.setWidth("100px");
		header9.setParent(head);
		
		Listheader header10 =new Listheader("qq");
		header10.setWidth("100px");
		header10.setParent(head);
		
		Listheader header11 =new Listheader("工作电话");
		header11.setWidth("100px");
		header11.setParent(head);
		Listheader header12 =new Listheader("家庭电话");
		header12.setWidth("100px");
		header12.setParent(head);
	}

}
